Page({
  data: {
    content: '',
    contact: '',
  },

  onLoad() {
    wx.setNavigationBarTitle({
      title: '意见反馈'
    });
  },

  onFeedbackInput(e) {
    this.setData({
      content: e.detail.value
    });
  },

  onContactInfoInput(e) {
    this.setData({
      contact: e.detail.value
    });
  },

  submitFeedback() {
    const { content, contact} = this.data;

    if (!content.trim()) {
      wx.showToast({
        title: '请填写反馈内容',
        icon: 'none',
        duration: 2000
      });
      return;
    }

    wx.showLoading({
      title: '提交中...',
      mask: true
    });

    // 在这里处理提交反馈的逻辑，例如发送到服务器
    wx.request({
      url: 'http://192.168.115.142:8080/api/feedback/submit', // 替换为您的后端 API 地址
      method: 'POST',
      data: {
        content: content,
        contact: contact
      },
      header: {
        'Content-Type': 'application/json', 
        'Authorization': 'Bearer ' + wx.getStorageSync('token')
      },
      success: (res) => {
        wx.hideLoading();
        console.log('反馈提交成功:', res);
        wx.showToast({
          title: '反馈已提交，感谢您的支持！',
          icon: 'success',
          duration: 2000,
          complete: () => {
            setTimeout(() => {
              wx.navigateBack(); // 提交成功后返回上一页
            }, 2000);
          }
        });
        this.setData({
        content: '',
          contact: ''
        });
      },
      fail: (err) => {
        wx.hideLoading();
        console.error('反馈提交失败:', err);
        wx.showToast({
          title: '提交失败，请稍后重试',
          icon: 'none',
          duration: 2000
        });
      }
    });
  }
});